
# removes word County from names
fix_VA_counties <- function(df){
  #df should be dataframe$county_variable
  counties_to_fix <- c('Covington city County','Danville city County',
                       'Emporia city County','Fairfax city County',
                       'Falls Church city County','Franklin city County',
                       'Fredericksburg city County','Galax city County',
                       'Hampton city County','Harrisonburg city County',
                       'Hopewell city County','Lexington city County',
                       'Lynchburg city County','Manassas city County',
                       'Manassas Park city County','Martinsville city County',
                       'Newport News city County','Norfolk city County',
                       'Norton city County','Petersburg city County',
                       'Poquoson city County','Portsmouth city County',
                       'Radford city County','Richmond city County',
                       'Roanoke city County','Salem city County',
                       'Staunton city County','Suffolk city County',
                       'Virginia Beach city County','Waynesboro city County',
                       'Williamsburg city County','Winchester city County',
                       'Alexandria city County','Bedford city County',
                       'Bristol city County','Buena Vista city County',
                       'Charlottesville city County','Chesapeake city County',
                       'Colonial Heights city County','Covington city County',
                       'Danville city County','Emporia city County',
                       'Fairfax city County','Falls Church city County',
                       'Franklin city County','Fredericksburg city County',
                       'Galax city County','Hampton city County',
                       'Harrisonburg city County','Hopewell city County',
                       'Lexington city County','Lynchburg city County',
                       'Manassas city County','Manassas Park city County',
                       'Martinsville city County','Newport News city County',
                       'Norfolk city County','Norton city County',
                       'Petersburg city County','Poquoson city County',
                       'Portsmouth city County','Radford city County',
                       'Richmond city County','Roanoke city County',
                       'Salem city County','Staunton city County',
                       'Suffolk city County','Virginia Beach city County',
                       'Waynesboro city County','Williamsburg city County',
                       'Winchester city County','Alexandria city County',
                       'Bedford city County','Bristol city County',
                       'Buena Vista city County','Charlottesville city County',
                       'Chesapeake city County','Colonial Heights city County',
                       'Covington city County','Danville city County',
                       'Emporia city County','Fairfax city County',
                       'Falls Church city County','Franklin city County',
                       'Fredericksburg city County','Galax city County',
                       'Hampton city County','Harrisonburg city County',
                       'Hopewell city County','Lexington city County',
                       'Lynchburg city County','Manassas city County',
                       'Manassas Park city County','Martinsville city County',
                       'Newport News city County','Norfolk city County',
                       'Norton city County','Petersburg city County',
                       'Poquoson city County','Portsmouth city County',
                       'Radford city County','Richmond city County',
                       'Roanoke city County','Salem city County',
                       'Staunton city County','Suffolk city County',
                       'Virginia Beach city County','Waynesboro city County',
                       'Williamsburg city County','Winchester city County',
                       'Alexandria city County','Bedford city County','Bristol city County','Buena Vista city County',
                       'Charlottesville city County','Chesapeake city County', 'Colonial Heights city County','Covington city County',
                       'Danville city County','Emporia city County','Fairfax city County','Falls Church city County',
                       'Franklin city County','Fredericksburg city County','Galax city County','Hampton city County',
                       'Harrisonburg city County','Hopewell city County','Lexington city County','Lynchburg city County',
                       'Manassas city County','Manassas Park city County','Martinsville city County','Newport News city County',
                       'Norfolk city County','Norton city County','Petersburg city County','Poquoson city County',
                       'Portsmouth city County','Radford city County','Richmond city County','Roanoke city County',
                       'Salem city County','Staunton city County','Suffolk city County','Virginia Beach city County',
                       'Waynesboro city County','Williamsburg city County','Winchester city County','Alexandria city County',
                       'Bristol city County','Buena Vista city County','Charlottesville city County','Chesapeake city County',
                       'Colonial Heights city County','Covington city County','Danville city County','Emporia city County',
                       'Fairfax city County','Falls Church city County','Franklin city County','Fredericksburg city County',
                       'Galax city County','Hampton city County','Harrisonburg city County','Hopewell city County',
                       'Lexington city County','Lynchburg city County','Manassas city County','Manassas Park city County',
                       'Martinsville city County','Newport News city County','Norfolk city County','Norton city County',
                       'Petersburg city County','Poquoson city County','Portsmouth city County','Radford city County',
                       'Richmond city County','Roanoke city County','Salem city County','Staunton city County','Suffolk city County',
                       'Virginia Beach city County','Waynesboro city County','Williamsburg city County','Winchester city County','Alexandria city County',
                       'Bristol city County','Buena Vista city County','Charlottesville city County','Chesapeake city County','Colonial Heights city County',
                       'Covington city County','Danville city County','Emporia city County','Fairfax city County','Falls Church city County','Franklin city County',
                       'Fredericksburg city County','Galax city County','Hampton city County','Harrisonburg city County','Hopewell city County','Lexington city County',
                       'Lynchburg city County','Manassas city County','Manassas Park city County','Martinsville city County','Newport News city County','Norfolk city County',
                       'Norton city County','Petersburg city County','Poquoson city County','Portsmouth city County','Radford city County','Richmond city County','Roanoke city County',
                       'Salem city County','Staunton city County','Suffolk city County','Virginia Beach city County','Waynesboro city County','Williamsburg city County','Winchester city County')
  fix <- which(df %in% counties_to_fix)
  df[fix] <- gsub(pattern=" County",x=df[fix],replacement="")
  return(df)
}


# create indicator for non-local agency ------
nonlocal <- c("section|\\bOPS\\b|\\bfield\\b|state|services|\\bLAW\\b|emergency|sergeant|\\barms\\b|assembly|\\bLEA\\b|\\bDIV\\b|\\bDNR\\b|enforcement|transit|admin|\\bDTA\\b|\\bport\\b|\\bENF\\b|\\bDPS\\b|railroad|justice|safety")


identify_nonlocal <- function(df){
  ## grab any agency that lists a state's initials
  states <- unique(df$state_abbrv)
  states[1] <- paste0("\\b",states[1])
  states[49] <- paste0(states[49],"\\b")
  colorado <- which(states=="CO")
  states <- states[-colorado]
  state_list <- paste(states,collapse = "\\b|\\b")
  
  nonlocal <- paste0(nonlocal,state_list)
  fix <- grep(nonlocal,df$agency_name,ignore.case = T)
  ## use these words to skip some that have been flagged from above
  ## example: HI_ED b/c local but often has the word state or state initials so gets flagged
  local <- c("\\bHI_ED\\b|\\bBATRE\\b|\\bDOTHAN\\b|\\bNAPIER\\b|DE QUEEN|ELM SPRINGS|LA PAZ|calaveras county sheriff|LA VERNE|PORT HUENEME|FORT COLLINS|LA JARA|LA PLATA COUNTY|HOWEY IN THE HILLS|NORTH PORT|PORT ORANGE|PORT SAINT LUCIE|AVONDALE ESTATES|PORT WENTWORTH|CAVE-IN-ROCK|LA CROSSE|DE PERE|DE FOREST|PORT TOWNSEND|PORT ORCHARD|PORT OF SEATTLE|PORT ANGELES|LA VERKIN|WALLER COUNTY|VIA METRO|PORT MANSFIELD|PORT LAVACA|PORT ISABEL|PORT ARTHUR|MONTGOMERY CTY|LIBERTY COUNTY|LA VILLA|LA SALLE|LA PORTE|LA MARQUE|LA JOYA|LA COSTE|JOHNSON|HOOD COUNTY|HIDALGO COUNTY|HARRIS CTY|DENTON COUNTY|DE LEON|DALLAS COUNTY|BEXAR COUNTY|NASHVILLE INTL|LA VERGNE|PORT ROYAL|FLORENCE REGIONAL|RIVER DAM|TOLEDO- LUCAS|PORT CLINTON|MEDWAY DRUG|GREATER CLEVELAND|GREATER ASHEVILLE|CUMBERLAND COUNTY ALCOHOL|BALD HEAD|ALBERT J ELLIS|WESTHAMPTON BEACH|PORT WASHINGTON|TRUTH OR CONSEQUENCES|MORIARTY POLICE|LEA COUNTY|WESTWOOD POLICE|PALISADES INTERSTATE|\\bLA VISTA POLICE|SPRINGFIELD BRANSON|MISSOURI CAPITOL|CLAY COUNTY|LA CRESCENT|PORT HURON|MT MORRIS|GENESEE COUNTY|BISHOP INTL|MBTA TRANSIT|LA PLATA|TENSAS|PORT BARRE|METRO TOPEKA|SERGEANT BLUFF|MAR-MAC|CLAY CO\\b|MT OLIVE|LAKE IN THE HILLS|JUSTICE POLICE|DANVILLE DEPT|CHICAGO HEIGHTS|PORT SAINT JOE|MELBOURNE INTL|DE BEQUE|CRESTED BUTTE MARSHALS|YOLO COUNTY|TEHAMA COUNTY|MERCED COUNTY DA|LOS ANGELES PORT|KERN COUNTY DA|FULTON EL CAMINO|CONTRA COSTA CTY|CALAVERAS COUNTY DA|TUCSON AIRPORT|TOMBSTONE MARSHAL|MOHAVE CO\\b|CAMP VERDE MARSHALS|UT COUNTY SHERIFF|DEKALB COUNTY STATE")
  donotfix <- grep(local,df$agency_name,ignore.case = T)
  fix <- fix[!fix %in% donotfix]
  df$local <- 1
  df$local[fix] <- 0
  return(df)
}

fix_county_names <- function(df){
  df$County <- as.character(df$County)
  df$County[df$agency_name=="PENNINGTON POLICE DEPT"] <- "Choctaw County"
  df$County[df$agency_name=="BLACK RIVER TECH COLLEGE PD HI_ED"] <- "Randolph County"
  df$County[df$agency_name=="MENIFEE POLICE DEPT"] <- "Conway County"
  df$County[df$agency_name=="REDFIELD POLICE DEPT"] <- "Jefferson County"
  df$County[df$agency_name=="ALASKA DEPT OF PUBLIC SAFETY LEA"] <- "Juneau City and Borough"
  df$County[df$agency_name=="JUNEAU POLICE DEPARTMENT"] <- "Juneau City and Borough"
  df$County[df$agency_name=="TEXARKANA POLICE DEPT" & df$State=="Arkansas"] <- "Miller County"
  df$County[df$agency_name=="TEXARKANA POLICE DEPT" & df$State=="Texas"] <- "Bowie County"
  df$County[df$agency_name=="ORO VALLEY POLICE DEPT"] <- "Pima County"
  df$County[df$agency_name=="ANCHORAGE POLICE DEPARTMENT"] <- "Anchorage Municipality"
  df$County[df$agency_name=="FAIRBANKS POLICE DEPT"] <- "Fairbanks North Star Borough"
  df$County[df$agency_name=="KODIAK POLICE DEPT"] <- "Kodiak Island Borough"
  df$County[df$agency_name=="NORTH POLE POLICE DEPT"] <- "Fairbanks North Star Borough"
  df$County[df$agency_name=="PARADISE VALLEY POLICE DEPT"] <- "Maricopa County"
  df$County[df$agency_name=="CA CORRECTIONAL SAFETY"] <- "Sacramento County"
  df$County[df$agency_name=="YAVAPAI COUNTY SHERIFF OFFICE"] <- "Yavapai County"
  df$County[df$agency_name=="LAWRENCE POLICE DEPT" & df$State=="Indiana"] <- "Marion County"
  df$County[df$agency_name=="LINDEN POLICE DEPT"& df$State=="Indiana"] <- "Montgomery County"
  df$County[df$agency_name=="MADISON POLICE DEPT"& df$State=="Indiana"] <- "Jefferson County"
  df$County[df$agency_name=="MARION POLICE DEPT"& df$State=="Indiana"] <- "Grant County"
  df$County[df$agency_name=="MILFORD POLICE DEPT"& df$State=="Indiana"] <- "Decatur County"
  df$County[df$agency_name=="CALHOUN COUNTY SHERIFF DEPT"] <- "Calhoun County"
  df$County[df$agency_name=="QUINLAN ISD POLICE DEPT K-12"] <- "Hunt County"
  df$County[df$agency_name=="DPS ETR  (LEA)"] <- "Travis County"
  df$County[df$agency_name=="BASTROP POLICE DEPT" & df$State=="Texas"] <- "Bastrop County"
  df$County[df$agency_name=="CANTON POLICE DEPARTMENT"] <- "Van Zandt County"
  df$County[df$agency_name=="PECOS POLICE DEPT"] <- "Reeves County"
  df$County[df$agency_name=="POLK COUNTY SHERIFFS OFFICE" & df$State=="Texas"] <- "Polk County"
  df$County[df$agency_name=="ROSEBUD POLICE DEPT"] <- "Falls County"
  df$County[df$agency_name=="SOUTHLAKE POLICE DEPT"] <- "Tarrant County"
  df$County[df$agency_name=="WORTHAM POLICE DEPARTMENT"] <- "Freestone County"
  df$County[df$agency_name=="ISLAND COUNTY SHERIFF OFFICE"] <- "Island County"
  df$County[df$agency_name=="OROVILLE POLICE DEPT"] <- "Okanogan County"
  df$County[df$agency_name=="KITSAP COUNTY SHERIFF OFFICE"] <- "Kitsap County"
  df$County[df$agency_name=="WHATCOM COUNTY SHERIFFS OFFICE"] <- "Whatcom County"
  df$County[df$agency_name=="TARPON SPRINGS POLICE DEPT"] <- "Pinellas County"
  df$County[df$agency_name=="WASHINGTON SCHOOL DIST POLICE K-12"] <- "Washington County"
  df$County[df$agency_name=="SODA SPRINGS POLICE DEPT"] <- "Caribou County"
  df$County[df$agency_name=="APPLE RIVER POLICE DEPT"] <- "Jo Daviess County"
  df$County[df$agency_name=="DANVERS POLICE DEPT"] <- "McLean County"
  df$County[df$agency_name=="IRVING POLICE DEPT"] <- "Montgomery County"
  df$County[df$agency_name=="MOUNDS POLICE DEPT"] <- "Pulaski County"
  df$County[df$agency_name=="WINSLOW POLICE DEPT" & df$State=="Illinois"] <- "Stephenson County"
  df$County[df$agency_name=="JAMESTOWN POLICE DEPT" & df$State=="Indiana"] <- "Boone County"
  df$County[df$agency_name=="UTICA POLICE DEPT"& df$State=="Indiana"] <- "Clark County"
  df$County[df$agency_name=="WA DEPT OF FISH  WILDLIFE ENF LEA"] <- "Thurston County"
  df$County[df$agency_name=="DPS SWAT- TEXAS RANGERS (LEA)"] <- "Travis County"
  df$County[df$agency_name=="CISCO COLLEGE PD HI_ED"] <- "Eastland County"
  df$County[df$agency_name=="PETERSBURG POLICE DEPT" & df$State=="Texs"] <- "Hale County"
  df$County[df$agency_name=="LINDSAY POLICE DEPT"] <- "Cooke County"
  df$County[df$agency_name=="MILLARD COUNTY SHERIFF"] <- "Millard County"
  df$County[df$agency_name=="FERNDALE POLICE DEPT"] <- "Whatcom County"
  df$County[df$agency_name=="SC PUBLIC SVC AUTH LAW ENF DIV LEA"] <- "Lexington County"
  df$County[df$agency_name=="COLLETON COUNTY SHERIFF OFFICE"] <- "Colleton County"
  df$County[df$agency_name=="HARTSVILLE POLICE DEPT"] <- "Darlington County"
  df$County[df$agency_name=="ORANGEBURG COUNTY SHERIFF DEPT"] <- "Orangeburg County"
  df$County[df$agency_name=="CORSON COUNTY SHERIFF OFFICE"] <- "Corson County"
  df$County[df$agency_name=="GROTON POLICE DEPT" & df$State=="South Dakota"] <- "Brown County"
  df$County[df$agency_name=="WELLS TWP POLICE DEPT"] <- "Jefferson County"
  df$County[df$agency_name=="SYRACUSE POLICE DEPT" & df$State=="Ohio"] <- "Meigs County"
  df$County[df$agency_name=="ST PARIS POLICE DEPT" & df$State=="Ohio"] <- "Champaign County"
  df$County[df$agency_name=="ROCKFORD POLICE DEPT" & df$State=="Ohio"] <- "Mercer County"
  df$County[df$agency_name=="WINTHROP POLICE DEPARTMENT" & df$State=="Minnesota"] <- "Sibley County"
  df$County[df$agency_name=="WESTBROOK POLICE DEPT" & df$State=="Minnesota"] <- "Cottonwood County"
  df$County[df$agency_name=="SAUK CENTRE POLICE DEPT" & df$State=="Minnesota"] <- "Stearns County"
  df$County[df$agency_name=="RICE POLICE DEPT" & df$State=="Minnesota"] <- "Benton County"
  df$County[df$agency_name=="MN DNR ENFORCEMENT DIV LEA" & df$State=="Minnesota"] <- "Ramsey County"
  df$County[df$agency_name=="HUTCHINSON POLICE DEPT" & df$State=="Minnesota"] <- "McLeod County"
  df$County[df$agency_name=="ELMORE POLICE DEPT" & df$State=="Minnesota"] <- "Faribault County"
  df$County[df$agency_name=="DAKOTA COUNTY SHERIFF OFFICE" & df$State=="Minnesota"] <- "Dakota County"
  df$County[df$agency_name=="ASSEMBLY SERGEANT AT ARMS (LEA)" & df$State=="California"] <- "Sacramento County"
  df$County[df$agency_name=="OFFICE OF PROTECTIVE SERVICES LEA" & df$State=="California"] <- "Sacramento County"
  df$County[df$agency_name=="CA OFFICE EMERGNCY SVCS LAW ENF LEA" & df$State=="California"] <- "Sacramento County"
  df$County[df$agency_name=="SADDLEBACK COLLEGE POLICE HI_ED" & df$State=="California"] <- "Orange County"
  df$County[df$agency_name=="FERNDALE POLICE DEPT" & df$State=="California"] <- "Humboldt County"
  df$County[df$agency_name=="BAY ST LOUIS POLICE DEPT" & df$State=="Mississippi"] <- "Hancock County"
  df$County[df$agency_name=="BROOKHAVEN POLICE DEPT" & df$State=="Mississippi"] <- "Lincoln County"
  df$County[df$agency_name=="DIAMONDHEAD POLICE DEPARTMENT" & df$State=="Mississippi"] <- "Hancock County"
  df$County[df$agency_name=="MS DEPT OF CORRECTIONS" & df$State=="Mississippi"] <- "Hinds County"
  df$County[df$agency_name=="VILLAGE OF HATCH POLICE DEPT" & df$State=="New Mexico"] <- "Dona Ana County"
  df$County[df$agency_name=="SUNLAND PARK POLICE DEPT" & df$State=="New Mexico"] <- "Dona Ana County"
  df$County[df$agency_name=="NM STATE UNIVERSITY POLICE HI_ED" & df$State=="New Mexico"] <- "Dona Ana County"
  df$County[df$agency_name=="NM MOUNTED PATROL" & df$State=="New Mexico"] <- "Chaves County"
  df$County[df$agency_name=="MORA COUNTY SHERIFF DEPT" & df$State=="New Mexico"] <- "Mora County"
  df$County[df$agency_name=="LAS CRUCES POLICE DEPT" & df$State=="New Mexico"] <- "Dona Ana County"
  df$County[df$agency_name=="DONA ANA COUNTY SHERIFFS DEPT" & df$State=="New Mexico"] <- "Dona Ana County"
  df$County[df$agency_name=="CARSON CITY SHERIFF OFFICE" & df$State=="Nevada"] <- "Carson City"
  df$County[df$agency_name=="NJ STATE POLICE-FIELD OPS SECTION" & df$State=="New Jersey"] <- "Mercer County"
  df$County[df$agency_name=="MORRISTOWN  BUREAU OF POLICE" & df$State=="New Jersey"] <- "Morris County"
  df$County[df$agency_name=="LEONIA POLICE DEPT" & df$State=="New Jersey"] <- "Bergen County"
  df$County[df$agency_name=="BARNEGAT TOWNSHIP POLICE DEPT" & df$State=="New Jersey"] <- "Ocean County"
  df$County[df$agency_name=="ONEIDA CITY POLICE DEPARTMENT" & df$State=="New York"] <- "Madison County"
  df$County[df$agency_name=="OXFORD POLICE DEPT" & df$State=="New York"] <- "Chenango County"
  df$County[df$agency_name=="SCOTTVILLE POLICE DEPT" & df$State=="Michigan"] <- "Mason County"
  df$County[df$agency_name=="RICHLAND POLICE DEPT" & df$State=="Michigan"] <- "Kalamazoo County"
  df$County[df$agency_name=="LAWTON POLICE DEPT" & df$State=="Michigan"] <- "Van Buren County"
  df$County[df$agency_name=="GLADSTONE PUBLIC SAFETY DEPT" & df$State=="Michigan"] <- "Delta County"
  df$County[df$agency_name=="FERNDALE POLICE DEPT" & df$State=="Michigan"] <- "Oakland County"
  df$County[df$agency_name=="DUNDEE POLICE DEPT" & df$State=="Michigan"] <- "Monroe County"
  df$County[df$agency_name=="AKRON POLICE DEPARTMENT" & df$State=="Michigan"] <- "Tuscola County"
  df$County[df$agency_name=="GRAND JUNCTION POLICE DEPT" & df$State=="Tennessee"] <- "Hardeman County"
  df$County[df$agency_name=="CLEMSON UNIVERSITY PD HI_ED" & df$State=="South Carolina"] <- "Oconee County"
  df$County[df$agency_name=="PA PORT AUTHORITY POLICE DEPT" & df$State=="Pennsylvania"] <- "Allegheny County"
  df$County[df$agency_name=="OK BUREAU OF NARCOTICS (LEA)" & df$State=="Oklahoma"] <- "Oklahoma County"
  df$County[df$agency_name=="OK 3RD DISTRICT ATTORNEY DTF LEA" & df$State=="Oklahoma"] <- "Oklahoma County"
  df$County[df$agency_name=="MORGAN STATE UNIV POLICE HI_ED" & df$State=="Maryland"] <- "Baltimore city"
  df$County[df$agency_name=="MD TRANSIT ADMIN POLICE DEPT" & df$State=="Maryland"] <- "Baltimore city"
  df$County[df$agency_name=="GARRETT COUNTY SHERIFF DEPT" & df$State=="Maryland"] <- "Garrett County"
  df$County[df$agency_name=="COPPIN STATE COLLEGE POLICE HI_ED" & df$State=="Maryland"] <- "Baltimore city"
  df$County[df$agency_name=="ANNE ARUNDEL COMM COLLEGE PD HI_ED" & df$State=="Maryland"] <- "Anne Arundel County"
  df$County[df$agency_name=="BALTIMORE CITY SHERIFF OFFICE" & df$State=="Maryland"] <- "Baltimore city"
  df$County[df$agency_name=="DELMAR POLICE DEPT" & df$State=="Delaware"] <- "Sussex County"
  df$County[df$agency_name=="DE DIV OF ALCOHOL  TABACCO ENF LEA" & df$State=="Delaware"] <- "Kent County"
  df$County[df$agency_name=="YALE UNIV POLICE DEPT  HI_ED" & df$State=="Connecticut"] <- "New Haven County"
  df$County[df$agency_name=="PARK COUNTY SHERIFF DEPT" & df$State=="Colorado"] <- "Park County"
  df$County[df$agency_name=="MINERAL COUNTY SHERIFF" & df$State=="Colorado"] <- "Mineral County"
  df$County[df$agency_name=="POWELL POLICE DEPT" & df$State=="Alabama"] <- "DeKalb County"
  df$County[df$agency_name=="NC DPS SPECIAL OPS INTEL UNIT" & df$State=="North Carolina"] <- "Wake County"
  df$County[df$agency_name=="PETERSBURG POLICE DEPT" & df$State=="Texas"] <- "Hale County"
  df$County[df$agency_name=="MOUNTRAIL COUNTY SHERIFF DEPT" & df$State=="North Dakota"] <- "Mountrail County"
  df$County[df$agency_name=="CLAY COUNTY SHERIFFS OFFICE" & df$State=="North Carolina"] <- "Clay County"
  df$County[df$agency_name=="DAVENPORT POLICE DEPT" & df$State=="Florida"] <- "Polk County"
  df$County[df$agency_name=="FL HIGHWAY PATROL" & df$State=="Florida"] <- "Orange County"
  df$County[df$agency_name=="GILCHRIST COUNTY SHERIFF DEPT" & df$State=="Florida"] <- "Gilchrist County"
  df$County[df$agency_name=="HALLANDALE BEACH POLICE DEPT" & df$State=="Florida"] <- "Broward County"
  df$County[df$agency_name=="KS DEPT OF WILDLIFE PRATT" & df$State=="Kansas"] <- "Pratt County"
  df$County[df$agency_name=="BEAUREGARD PARISH SHERIFF DEPT" & df$State=="Louisiana"] <- "Beauregard Parish"
  df$County[df$agency_name=="BOSTON AND MAINE RAILROAD POLICE" & df$State=="Maine"] <- "Kennebec County"
  df$County[df$agency_name=="KNOX COUNTY SHERIFF DEPT" & df$State=="Maine"] <- "Knox County"
  df$County[df$agency_name=="GOSHEN POLICE DEPT" & df$State=="Massachusetts"] <- "Hampshire County"
  df$County[df$agency_name=="WARREN POLICE DEPT" & df$State=="Massachusetts"] <- "Worcester County"
  df$County[df$agency_name=="SADDLEBACK COLLEGE POLICE  HI_ED" & df$State=="California"] <- "Orange County"
  df$County[df$agency_name=="ALTON POLICE DEPT" & df$State=="Texas"] <- "Hidalgo County"
  df$County[df$agency_name=="HOCKING COLLEGE POLICE DEPT HI_ED" & df$State == "Ohio"] <- "Athens County"
  return(df)
  
}
